package com.example.im.bean

import androidx.room.*
import com.example.im.bean.converters.AitsConverters
import com.example.im.bean.converters.FileConverters
import java.io.Serializable

@Entity(
    foreignKeys = [ForeignKey(
        entity = UserRoom::class,
        parentColumns = ["id"],
        childColumns = ["u_id"],
        onDelete = ForeignKey.CASCADE
    )], indices = [Index(value = ["encrypt"], unique = true)]
)
@TypeConverters(AitsConverters::class, FileConverters::class)
class ChatRecord : Serializable {

    @PrimaryKey(autoGenerate = true)
    var id: Int = 0//表ID
    @ColumnInfo(name = "u_id")
    var uid: Int = 0//用户表ID
    @ColumnInfo(name = "from")
    var from: String? = null//消息来自谁
    @ColumnInfo(name = "to")
    var to: String? = null//消息接收者
    @ColumnInfo(name = "body")
    var body: String? = null//消息内容
    @ColumnInfo(name = "aits")
    var aits: Set<String>? = null//艾特信息
    @ColumnInfo(name = "time")
    var time: Long = 0//接收发送时间
    @ColumnInfo(name = "type")
    var type: Int = 0//消息类型
    @ColumnInfo(name = "kind")
    var kind: Int = 0//单聊1,群聊2
    @ColumnInfo(name = "or")
    var or: Int = 0//接收2,发送1
    @ColumnInfo(name = "status")
    var status: Int = 0//发送成功1,发送进行中2,发送失败3
    @ColumnInfo(name = "file")
    var file: FileInfo? = null//文件信息
    @ColumnInfo(name = "encrypt")
    var encrypt: String? = null//加密
    @ColumnInfo(name = "json")
    var json: String? = null

    fun getChatRecord(): ChatRecord = this

    companion object {
        private const val serialVersionUID = 42L
    }
}